import java.util.Deque;
import java.util.LinkedList;

class Solution1 {
    public static void main(String[] args) {
        System.out.println(isValid("()"));
    }
    public static boolean isValid(String s) {
        Deque<Character> stcak = new LinkedList<>();
        char tmp;
        for (int i = 0; i < s.length(); i++) {
            tmp = s.charAt(i);
            if(tmp=='('||tmp=='['||tmp=='{')
                stcak.push(tmp);
            else {
                if(stcak.isEmpty()){
                    return false;
                }
                char top = stcak.peek();
                if (top=='('&&tmp==')'||top=='{'&&tmp=='}'||top=='['&&tmp==']') {
                    stcak.pop();
                }
                else return false;

            }
        }
        if(!stcak.isEmpty()) return false;
        return true;
    }
}